/**********************************************************************************************/
/* FBL_LogFile_Imp.cpp                                                      				  */
/*                                                                       					  */
/* Copyright Paradigma, 1993-2006															  */
/* All Rights Reserved                                                   					  */
/**********************************************************************************************/

#include <VShared/FBL/publ/Headers/StdAfx.h>

#include <VShared/FBL/publ/TestTools/FBL_LogFile_Imp.h>

#include <VShared/FBL/publ/Interfaces/FBL_I_IStream.h>
#include <VShared/FBL/publ/Interfaces/FBL_I_Disk_Location.h>


/**********************************************************************************************/
FBL_Begin_Namespace


/**********************************************************************************************/
I_LogFile* CreateLogFile( 
	const String& 	inLogFileName, 
	uchar 			inVerboseLevel, 
	bool 			inFlushEachStep )
{
	I_LogFile* lf = new FBL::LogFile_Imp( inLogFileName, inVerboseLevel, inFlushEachStep );

	return lf;
}

 
/**********************************************************************************************/
I_LogFile* CreateLogFile( 
	const String& 	inLogFolderPath, 
	const String& 	inLogFileName, 
	uchar 			inVerboseLevel, 
	bool 			inFlushEachStep )
{
	I_LogFile* lf = new FBL::LogFile_Imp( 
										inLogFolderPath, 
										inLogFileName, 
										inVerboseLevel, 
										inFlushEachStep );

	return lf;
}


#pragma mark -


/**********************************************************************************************/
LogFile_Imp::LogFile_Imp( 
	const String& 	inLogFileName, 
	uchar 			inVerboseLevel,
	bool	 		inFlushEachStep )
{
	mVerboseLevel = inVerboseLevel;
	mFlushEachStep = inFlushEachStep;

	I_Location_Ptr pLoc = I_Disk_Location::GetAppLocation()->
							get_ChildLocation( inLogFileName.c_str() );

	Init( pLoc );
}


/**********************************************************************************************/
LogFile_Imp::LogFile_Imp( 
	const String& 	inLogFolderPath,
	const String& 	inLogFileName, 
	uchar 			inVerboseLevel,
	bool	 		inFlushEachStep )
{
	mVerboseLevel = inVerboseLevel;
	mFlushEachStep = inFlushEachStep;

	I_Location_Ptr pLoc = CreateDiskLocation( (inLogFolderPath + inLogFileName).c_str() );

	Init( pLoc );
}



/**********************************************************************************************/
void LogFile_Imp::Init( I_Location_Ptr	inLocation )
{
    I_IStream_Ptr pIStream = CreateTextStream( 
							dynamic_cast<I_Disk_Location*>( inLocation.get() ) );
	 
	 // RZ: replaced on dynamic_cast to NOT log this dynamic_cast.
	 // Otheriwse we get loop.
	 //
	 // mpStream = fbl_dynamic_cast<I_OStream>( pIStream );
	 mpStream = dynamic_cast<I_OStream*>( pIStream.get() );
}

/**********************************************************************************************/
LogFile_Imp::~LogFile_Imp( void )
{
	//if( mpStream )
	//	delete mpStream;
}


/**********************************************************************************************/
void LogFile_Imp::Flush( void )
{
	mpStream->Flush();
}


/**********************************************************************************************/
void LogFile_Imp::Close( void )
{
	Flush();
	mpStream->Close();
}


#pragma mark -


/**********************************************************************************************/
LogFile_Imp& LogFile_Imp::operator<<( char s )
{
	mpStream->put(s);
	
	if( mFlushEachStep )
		mpStream->Flush();
	
	return *this;
}


/**********************************************************************************************/
LogFile_Imp& LogFile_Imp::operator<<( uchar s )
{
	mpStream->put(s);
	
	if( mFlushEachStep )
		mpStream->Flush();
	
	return *this;
}


/**********************************************************************************************/
LogFile_Imp& LogFile_Imp::operator<<( short s )
{
	mpStream->put(s);
	
	if( mFlushEachStep )
		mpStream->Flush();
	
	return *this;
}


/**********************************************************************************************/
LogFile_Imp& LogFile_Imp::operator<<( ushort s )
{
	mpStream->put(s);
	
	if( mFlushEachStep )
		mpStream->Flush();
	
	return *this;
}


/**********************************************************************************************/
LogFile_Imp& LogFile_Imp::operator<<( long s )
{
	mpStream->put(s);
	
	if( mFlushEachStep )
		mpStream->Flush();
	
	return *this;
}


/**********************************************************************************************/
LogFile_Imp& LogFile_Imp::operator<<( ulong s )
{
	mpStream->put(s);
	
	if( mFlushEachStep )
		mpStream->Flush();
	
	return *this;
}


/**********************************************************************************************/
LogFile_Imp& LogFile_Imp::operator<<( llong s )
{
	mpStream->put(s);
	
	if( mFlushEachStep )
		mpStream->Flush();
	
	return *this;
}


/**********************************************************************************************/
LogFile_Imp& LogFile_Imp::operator<<( ullong s )
{
	mpStream->put(s);
	
	if( mFlushEachStep )
		mpStream->Flush();
	
	return *this;
}


/**********************************************************************************************/
LogFile_Imp& LogFile_Imp::operator<<( float s )
{
	mpStream->put(s);
	
	if( mFlushEachStep )
		mpStream->Flush();
	
	return *this;
}


/**********************************************************************************************/
LogFile_Imp& LogFile_Imp::operator<<( double s )
{
	mpStream->put(s);
	
	if( mFlushEachStep )
		mpStream->Flush();
	
	return *this;
}


/**********************************************************************************************/
LogFile_Imp& LogFile_Imp::operator<<( const char* s )
{
	mpStream->put( s );
	
	if( mFlushEachStep )
		mpStream->Flush();
	
	return *this;
}


/**********************************************************************************************/
LogFile_Imp& LogFile_Imp::operator<<( const UChar* s )
{
	mpStream->put( s );
		
	if( mFlushEachStep )
		mpStream->Flush();
	
	return *this;
}

/**********************************************************************************************/
FBL_End_Namespace
